package redbook;

import java.util.Scanner;

/**
 * @author blh
 * @date 2024年06月28日 10:58
 */

public class Main {

    static int min = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (n == 1) {
            System.out.println(a[0]);
        }
        // 将数组分成两组，绝对值最小
        countMin(a, 0, 0);
        System.out.println(min);
    }

    private static void countMin(int[] a, int curIndex, int curSum) {
        if (curIndex == a.length) {
            return;
        }
        int minus = Math.abs(curSum - a[curIndex]);
        int add = Math.abs(curSum + a[curIndex]);
        if (curIndex == a.length - 1) {
            min = Math.min(Math.min(minus, add), min);
        }
        countMin(a, curIndex + 1, minus);
        countMin(a, curIndex + 1, add);
    }
}
